home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / p_light.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-20  |  2.4 KB  |  92 lines

  1. // Flashlight patch, by Dustin Ridenbaugh, TheGunslinger@ecr.net
  2.  
  3. #include "g_local.h"
  4.  
  5.  
  6. /*
  7. 8===============>
  8. FL_make
  9. make the dang thing
  10. <===============8
  11. */
  12.  
  13. void FL_make(edict_t *self) 
  14. {
  15.     vec3_t    start,forward,right,end;
  16.  
  17.      if ( self->flashlight )
  18.     {
  19.         gi.sound(self, CHAN_VOICE, gi.soundindex("weapons/lightoff.wav"), 1, ATTN_NORM, 0);
  20.         PlayerNoise(self, self->s.origin, PNOISE_SELF);
  21.         G_FreeEdict(self->flashlight);
  22.         self->flashlight = NULL;
  23.         return;
  24.     }
  25.     gi.sound(self, CHAN_VOICE, gi.soundindex("weapons/lighton.wav"), 1, ATTN_NORM, 0);
  26.     PlayerNoise(self, self->s.origin, PNOISE_SELF);
  27.     AngleVectors (self->client->v_angle, forward, right, NULL);
  28.  
  29.     VectorSet(end,100 , 0, 0);
  30.     G_ProjectSource (self->s.origin, end, forward, right, start);
  31.  
  32.     self->flashlight = G_Spawn ();
  33.     self->flashlight->owner = self;
  34.     self->flashlight->movetype = MOVETYPE_NOCLIP;
  35.     self->flashlight->solid = SOLID_NOT;
  36.     self->flashlight->classname = "flashlight";
  37.     self->flashlight->s.modelindex = gi.modelindex ("models/objects/blank/tris.md2");    // HEY KIDDYS NOTE THIS
  38.     self->flashlight->s.skinnum = 0;
  39.     self->flashlight->s.effects |= EF_HYPERBLASTER;        // Other effects can be used here, such as flag1, but these look corney and 
  40.                                 // dull. Try stuff and tell me if you find anything cool
  41.     self->flashlight->s.renderfx |= RF_TRANSLUCENT;
  42.  
  43.     self->flashlight->think = FL_think;
  44.     self->flashlight->nextthink = level.time + 0.1;
  45. }
  46.  
  47. // Congratulations, and welcome to the middle of the file.
  48.  
  49. /*
  50. 8===============>
  51. FL_make
  52. make the dang thing
  53. <===============8
  54. */
  55.  
  56. void FL_think (edict_t *self)
  57. {
  58.     vec3_t start,end,endp,offset;
  59.     vec3_t forward,right,up;
  60.     trace_t tr;
  61.  
  62.     AngleVectors (self->owner->client->v_angle, forward, right, up);
  63.  
  64.     VectorSet(offset,24 , 6, self->owner->viewheight-7);
  65.     G_ProjectSource (self->owner->s.origin, offset, forward, right, start);
  66.     VectorMA(start,8192,forward,end);
  67.  
  68.     tr = gi.trace (start,NULL,NULL, end,self->owner,CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
  69.  
  70.     if (tr.fraction != 1)
  71.     {
  72.         VectorMA(tr.endpos,-4,forward,endp);
  73.         VectorCopy(endp,tr.endpos);
  74.     }
  75.  
  76.     if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
  77.     {
  78.         if ((tr.ent->takedamage) && (tr.ent != self->owner))
  79.         {
  80.             self->s.skinnum = 1;
  81.         }
  82.     }
  83.     else
  84.         self->s.skinnum = 0;
  85.  
  86.     vectoangles(tr.plane.normal,self->s.angles);
  87.     VectorCopy(tr.endpos,self->s.origin);
  88.  
  89.     gi.linkentity (self);
  90.     self->nextthink = level.time + 0.1;
  91. }
  92.